----------------------------------------------------------------------------------
      name:  <unnamed>
       log:  C:\research\china\decentralization\restat_data\tabdata\dofiles\tab_da
> ta\tabdata1.log
  log type:  text
 opened on:  22 Jul 2016, 09:50:16

. 
. ************************ 1. Prepare various tabular sources for merging ********
> *************************
. 
. use ..\..\data\tabular_data_BJ\source\ind_yb_rz.dta

. ***Fix these unit_status which are wrong
. replace unit_status=5 if unit_code_08==130200 & year==1995
(1 real change made)

. replace unit_status=5 if unit_code_08==130200 & year==2000
(0 real changes made)

. replace unit_status=5 if unit_code_08==130200 & year==2005
(0 real changes made)

. replace unit_status=4 if unit_code_08==130201 & year==1995
(1 real change made)

. replace unit_status=4 if unit_code_08==130201 & year==2000
(0 real changes made)

. replace unit_status=4 if unit_code_08==130201 & year==2005
(0 real changes made)

. replace unit_status=5 if unit_code_08==130400 & year==1995
(0 real changes made)

. replace unit_status=4 if unit_code_08==130401 & year==1995
(0 real changes made)

. replace unit_status=5 if unit_code_08==510300 & year==2000
(0 real changes made)

. replace unit_status=4 if unit_code_08==510301 & year==2000
(0 real changes made)

. keep if unit_status==4
(4,022 observations deleted)

. *** These are empty, probably because they are cities that had not yet been prom
> oted
. drop if unit_code_08==222401
(2 observations deleted)

. drop if unit_code_08==341601
(3 observations deleted)

. drop if unit_code_08==422801
(2 observations deleted)

. drop if unit_code_08==433101
(1 observation deleted)

. drop if unit_code_08==441901
(3 observations deleted)

. drop if unit_code_08==442001
(4 observations deleted)

. gen city_code = unit_code_08

. replace city_code = unit_code_08-100 if city_code-10*int(city_code/10)==0
(20 real changes made)

. replace city_code = unit_code_08-1 if city_code-10*int(city_code/10)==1
(315 real changes made)

. sort city_code year

. save temp_indyb.dta, replace
(note: file temp_indyb.dta not found)
file temp_indyb.dta saved

. 
. use ..\..\data\tabular_data_BJ\source\PY_ADCP_final_rz.dta

. sort unit_code year

. save ..\..\data\tabular_data_BJ\source\PY_ADCP_final_rz.dta, replace
file ..\..\data\tabular_data_BJ\source\PY_ADCP_final_rz.dta saved

. 
. use ..\..\data\tabular_data_BJ\source\PY_2YCP_final_rz.dta

. sort unit_code year 

. merge unit_code year using ..\..\data\tabular_data_BJ\source\PY_ADCP_final_rz, u
> pdate
(note: you are using old merge syntax; see [D] merge for new syntax)

. tab _merge

     _merge |      Freq.     Percent        Cum.
------------+-----------------------------------
          2 |      1,986       66.67       66.67
          3 |        993       33.33      100.00
------------+-----------------------------------
      Total |      2,979      100.00

. drop _merge

. keep if year==1990|year==1995
(2,317 observations deleted)

. gen city_code = unit_code

. replace city_code = unit_code-100 if city_code-10*int(city_code/10)==0
(8 real changes made)

. replace city_code = unit_code-1 if city_code-10*int(city_code/10)==1
(654 real changes made)

. rename gdp gdp_py

. rename givo givo_py

. rename fdi fdi_py

. sort city_code year

. save temp_2ycp.dta, replace
(note: file temp_2ycp.dta not found)
file temp_2ycp.dta saved

. 
. use ..\..\data\tabular_data_BJ\source\MI_4YCP.dta

. rename total_pop pop

. rename avg_salary_of_staff_worker avgsalary_michigan

. rename gdp gdp_michigan

. rename gdp_sector2 gdp_sector2_mi

. rename gdp_sector3 gdp_sector3_mi

. sort city_code year

. save temp_mi3ycp.dta, replace
(note: file temp_mi3ycp.dta not found)
file temp_mi3ycp.dta saved

. 
. use ..\..\data\tabular_data_BJ\source\MI_ADCP.dta

. sort city_code year

. save ..\..\data\tabular_data_BJ\source\MI_ADCP.dta, replace
file ..\..\data\tabular_data_BJ\source\MI_ADCP.dta saved

. 
. ** Professor Zhang's dijishi.csv
. insheet using ..\..\data\tabular_data_BJ\source\asset_dijishi.csv, clear
(14 vars, 858 obs)

. rename city05 city_code

. rename gross_asset_cp asset_g_qz

. rename net_asset_cp asset_n_qz

. rename city_name city_namex

. keep city_code year asset_g_qz asset_n_qz

. sort city_code year

. save temp_qz3.dta, replace
(note: file temp_qz3.dta not found)
file temp_qz3.dta saved

. *2005 Asset Data
. insheet using ..\..\data\tabular_data_BJ\source\assets_05.csv, clear
(7 vars, 286 obs)

. rename city05 city_code

. rename net_asset_cp asset_n_qz

. rename city_name city_namex

. keep city_code year asset_n_qz

. append using temp_qz3.dta

. sort city_code year

. save temp_qz3.dta, replace
file temp_qz3.dta saved

. 
. 
. /****** 2. Merge Data Sets to Correspondence Table Using 
>                                         City Proper/Year Units Only ********/
. 
. *** Create a data set at the city proper/year level using 2008/defn prefectures
. use ..\..\data\correspondence_tables\generated\correspondence_82_10.dta

. keep if unit_status==1
(12,328 observations deleted)

. keep province_name province_code city_code city_name city05 year

. sort city_code year

. by city_code year: keep if _n==1
(3,378 observations deleted)

. sort city_code year

. 
. *** Individual Yearbook
. merge city_code year using temp_indyb.dta
(note: you are using old merge syntax; see [D] merge for new syntax)
(note: variable city_code was long, now double to accommodate using data's
       values)

. tab year _merge

           |        _merge
      year |         1          3 |     Total
-----------+----------------------+----------
      1982 |        93          0 |        93 
      1990 |       143         29 |       172 
      1995 |       147         50 |       197 
      2000 |       158         89 |       247 
      2005 |       168        100 |       268 
      2008 |       201         67 |       268 
      2010 |       268          0 |       268 
-----------+----------------------+----------
     Total |     1,178        335 |     1,513 


. rename _merge mrg_ind

. 
. *** Printed Yearbooks
. sort city_code year

. merge city_code year using temp_2ycp.dta
(note: you are using old merge syntax; see [D] merge for new syntax)

. tab year _merge

           |              _merge
      year |         1          2          3 |     Total
-----------+---------------------------------+----------
      1982 |        93          0          0 |        93 
      1990 |         0        159        172 |       331 
      1995 |         0        134        197 |       331 
      2000 |       247          0          0 |       247 
      2005 |       268          0          0 |       268 
      2008 |       268          0          0 |       268 
      2010 |       268          0          0 |       268 
-----------+---------------------------------+----------
     Total |     1,144        293        369 |     1,806 


. *** These are county cities before promotion to prefecture cities
. drop if _merge==2
(293 observations deleted)

. rename _merge mrg_PY2Y

. 
. sort city_code year

. merge city_code year using temp_mi3ycp.dta
(note: you are using old merge syntax; see [D] merge for new syntax)
(note: variable year was int, now float to accommodate using data's values)
(note: variable city_name was str29, now str34 to accommodate using data's
       values)
(note: variable unit_status was byte, now float to accommodate using data's
       values)
(note: variable unit_code_08 was long, now double to accommodate using data's
       values)

. tab year _merge

           |              _merge
      year |         1          2          3 |     Total
-----------+---------------------------------+----------
      1982 |        93          0          0 |        93 
      1990 |       172          0          0 |       172 
      1995 |       197          0          0 |       197 
      2000 |         0         20        247 |       267 
      2005 |         0          2        268 |       270 
      2008 |         0          2        268 |       270 
      2010 |         0          2        268 |       270 
-----------+---------------------------------+----------
     Total |       462         26      1,051 |     1,539 


. *** This is the special county cities handled elsewhere or missing b/c not yet p
> romoted
. drop if _merge==2
(26 observations deleted)

. rename _merge mrg_MI3Y

. 
. sort city_code year

. merge city_code year using ..\..\data\tabular_data_BJ\source\MI_ADCP.dta
(note: you are using old merge syntax; see [D] merge for new syntax)
(note: variable province was str12, now str14 to accommodate using data's
       values)

. tab year _merge

           |              _merge
      year |         1          2          3 |     Total
-----------+---------------------------------+----------
      1982 |        93          0          0 |        93 
      1990 |       172          0          0 |       172 
      1995 |       197          0          0 |       197 
      1996 |         0        207          0 |       207 
      1997 |         0        214          0 |       214 
      1998 |         0        219          0 |       219 
      1999 |         0        226          0 |       226 
      2000 |         0          3        247 |       250 
      2001 |         0        254          0 |       254 
      2002 |         0        264          0 |       264 
      2003 |         0        269          0 |       269 
      2004 |         0        270          0 |       270 
      2005 |         0          2        268 |       270 
      2006 |         0        270          0 |       270 
      2007 |         0        270          0 |       270 
      2008 |         0          2        268 |       270 
      2009 |         0        270          0 |       270 
      2010 |         0          2        268 |       270 
-----------+---------------------------------+----------
     Total |       462      2,742      1,051 |     4,255 


. *** This is 2 extra prefectures and extra years + county cities handled elsewher
> e
. drop if _merge==2
(2,742 observations deleted)

. rename _merge mrg_MIAD

. drop mrg_*

. 
. ** Professor Zhang's dijishi_90_00_10_asset.csv (HY 08/09/12)
. 
. sort city_code year

. merge city_code year using temp_qz3.dta
(note: you are using old merge syntax; see [D] merge for new syntax)

. tab year _merge

           |              _merge
      year |         1          2          3 |     Total
-----------+---------------------------------+----------
      1982 |        93          0          0 |        93 
      1990 |         0        114        172 |       286 
      1995 |       197          0          0 |       197 
      2000 |         0         39        247 |       286 
      2005 |         0         18        268 |       286 
      2008 |       268          0          0 |       268 
      2010 |         0         18        268 |       286 
-----------+---------------------------------+----------
     Total |       558        189        955 |     1,702 


. ** _merge=2 are outside our study area or for full prefecs only (no CP yet)
. save temp.dta, replace
(note: file temp.dta not found)
file temp.dta saved

. keep if _merge==2
(1,513 observations deleted)

. keep city_code year asset_*

. rename city_code city05

. drop if asset_n_qz==.
(110 observations deleted)

. rename asset_n_qz asset_n_qzx

. rename asset_g_qz asset_g_qzx

. sort city05 year

. save ..\..\data\tabular_data_BJ\generated\asset_data.dta, replace
file ..\..\data\tabular_data_BJ\generated\asset_data.dta saved

. use temp.dta

. drop if _merge==2
(189 observations deleted)

. rename _merge mrg_QZ3

. 
. drop mrg_*

. 
. mvdecode totemp total_pop-num_colstd emp_sect2-emp_sect3, mv(-99)
      totemp: 1 missing value generated
   total_pop: 1 missing value generated
        kmpr: 1 missing value generated
         apr: 1 missing value generated
        prpc: 1 missing value generated
      num_bt: 1 missing value generated
   avgsalary: 1 missing value generated
  num_colstd: 1 missing value generated
   emp_sect2: 1 missing value generated
   emp_sect3: 1 missing value generated

. mvdecode totemp-fdi_py, mv(-9)
      totemp: 9 missing values generated
      gdp_py: 10 missing values generated
   gdp_sect2: 10 missing values generated
   gdp_sect3: 10 missing values generated
   total_pop: 10 missing values generated
        kmpr: 179 missing values generated
         apr: 198 missing values generated
        prpc: 9 missing values generated
      num_bt: 16 missing values generated
   avgsalary: 10 missing values generated
  num_colstd: 60 missing values generated
     givo_py: 9 missing values generated
    givo_soe: 198 missing values generated
   givo_colt: 198 missing values generated
     exp_lgt: 3 missing values generated
    num_hedu: 33 missing values generated
   publibcol: 6 missing values generated
     culland: 172 missing values generated
        area: 2 missing values generated
   emp_sect2: 9 missing values generated
   emp_sect3: 9 missing values generated
   fixinvest: 6 missing values generated
      fdi_py: 53 missing values generated

. replace gdp_py = . if gdp_py<0
(1 real change made, 1 to missing)

. replace gdp_sect2 = . if gdp_sect2<0
(1 real change made, 1 to missing)

. replace gdp_sect3 = . if gdp_sect3<0
(1 real change made, 1 to missing)

. replace givo = . if givo<0
(0 real changes made)

. replace givo_soe = . if givo_soe<0
(1 real change made, 1 to missing)

. replace givo_colt = . if givo_colt<0
(1 real change made, 1 to missing)

. 
. *** Label Variables
. label variable gdp "(ind yrb)"

. label variable nnp "(ind yrb)"

. label variable gdp_sector1 "(ind yrb)"

. label variable nnp_sector1 "(ind yrb)"

. label variable gdp_sector2 "(ind yrb)"

. label variable nnp_sector2 "(ind yrb)"

. label variable gdp_sector3 "(ind yrb)"

. label variable nnp_sector3 "(ind yrb)"

. label variable tot_pop "(ind yrb)"

. label variable r08_gdp "(ind yrb)"

. label variable r08_nnp "(ind yrb)"

. label variable r08_gdp_sector2 "(ind yrb)"

. label variable r08_nnp_sector2 "(ind yrb)"

. label variable r08_gdp_sector3 "(ind yrb)"

. label variable r08_nnp_sector3 "(ind yrb)"

. label variable r08_tot_pop "(ind yrb)"

. label variable num_car "(ind yrb)"

. label variable dust_ems "(ind yrb)"

. label variable gas_ems "(ind yrb)"

. label variable so2 "(ind yrb)"

. label variable kproad "(ind yrb)"

. label variable aproad "(ind yrb)"

. label variable bustrly "(ind yrb)"

. label variable numhins "(ind yrb)"

. label variable arrived_fdi "(ind yrb)"

. label variable tot_emp "(ind yrb)"

. label variable tot_emp_sect2 "(ind yrb)"

. label variable tot_emp_sect3 "(ind yrb)"

. label variable giov "(ind yrb)"

. label variable giov_soecol "(ind yrb)"

. label variable tot_area "(ind yrb)"

. label variable giov_new "(ind yrb)"

. label variable giov_soecol_new "(ind yrb)"

. label variable totemp "(py)"

. label variable agremp "(py)"

. label variable minemp "(py)"

. label variable manuemp "(py)"

. label variable egwemp "(py)"

. label variable constemp "(py)"

. label variable geolemp "(py)"

. label variable tstemp "(py)"

. label variable whoreemp "(py)"

. label variable fininsemp "(py)"

. label variable reemp "(py)"

. label variable ssemp "(py)"

. label variable hsemp "(py)"

. label variable ecmemp "(py)"

. label variable stemp "(py)"

. label variable pubemp "(py)"

. label variable gdp_py "(py)"

. label variable gdp_sect2 "(py)"

. label variable gdp_sect3 "(py)"

. label variable total_pop "(py)"

. label variable kmpr "(py)"

. label variable apr "(py)"

. label variable prpc "(py)"

. label variable num_bt "(py)"

. label variable so2 "(py)"

. label variable avgsalary "(py)"

. label variable num_colstd "(py)"

. label variable givo_py "(py)"

. label variable givo_soe "(py)"

. label variable givo_colt "(py)"

. label variable exp_lgt "(py)"

. label variable num_hedu "(py)"

. label variable publibcol "(py)"

. label variable culland "(py)"

. label variable area "(py)"

. label variable emp_sect2 "(py)"

. label variable emp_sect3 "(py)"

. label variable unit_status "(py)"

. label variable fixinvest "(py)"

. label variable fdi_py "(py)"

. label variable asset_g_qz "Gross Assets (QZ)"

. label variable asset_n_qz "Net Assets (QZ)"

. 
. sort city05 year

. save ../../data/tabular_data_BJ/generated/cpt.dta, replace
file ../../data/tabular_data_BJ/generated/cpt.dta saved

. 
. *** This used to build 1990 and 2010 GDP imputations
. keep if year==1990 | year==2010
(1,073 observations deleted)

. keep city05 year gdp_py gdp_sect2 gdp_sect3 gdp_michigan gdp_sector2_mi gdp_sect
> or3_mi

. rename gdp_py cgdp_py

. rename gdp_sect2 cgdp_sect2

. rename gdp_sect3 cgdp_sect3

. replace cgdp_py = gdp_michigan if year==2010
(268 real changes made)

. replace cgdp_sect2 = gdp_sector2_mi if year==2010
(268 real changes made)

. replace cgdp_sect3 = gdp_sector3_mi if year==2010
(268 real changes made)

. drop if cgdp_py==.
(3 observations deleted)

. drop gdp_sector2_mi gdp_sector3_mi gdp_michigan

. sort city05 year

. save ../../data/tabular_data_BJ/generated/cp90_gdp.dta, replace
file ../../data/tabular_data_BJ/generated/cp90_gdp.dta saved

. 
. **** This is use to build 2010 GDP Imputations
. use ..\..\data\tabular_data_BJ\source\MI_4YPF.dta

. keep if year==2010
(807 observations deleted)

. rename gdp pgdp_py

. rename gdp_sector2 pgdp_sect2

. rename gdp_sector3 pgdp_sect3

. rename city_code city05

. keep city05 year pgdp_*

. sort city05 year

. save ../../data/tabular_data_BJ/generated/pf10_gdp.dta, replace
file ../../data/tabular_data_BJ/generated/pf10_gdp.dta saved

. 
. 
. log close
      name:  <unnamed>
       log:  C:\research\china\decentralization\restat_data\tabdata\dofiles\tab_da
> ta\tabdata1.log
  log type:  text
 closed on:  22 Jul 2016, 09:50:16
----------------------------------------------------------------------------------
